#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>


template <class myType, class myTypeContainer>
class tContainer_t 
{	
	typedef typename myTypeContainer::iterator containerIter;

	class predicate
	{
	private:
		const myType* predVal;
	public:
		predicate(const myType* t)
		{
			predVal = t;
		}
		bool operator() (myType* t) const
		{
			return (*t == *predVal);
		}
	};

private:
	myTypeContainer container;

public:
	tContainer_t() 
	{
	}

	tContainer_t(const tContainer_t &other)
	{
		container = other.container;
	}

	tContainer_t &operator=(const tContainer_t &other)
	{
		if (this != &other)
		{
			container = other.container;
		}
		return *this;
	}

	bool isEmpty() const
	{
		return container.empty();
	}

	int numberOfElements() const 
	{
		return container.size();
	}

	void insertNewElement(myType* elem)
	{
		container.push_back(elem);
	}

	myType* getFirstElement() const
	{
		if (!isEmpty())
		{
			return container.front();
		}
		else 
		{
			return 0;
		}
	}

	myType* getLastElement() const
	{
		if (!isEmpty())
		{
			return container.back();
		}
		else 
		{
			return 0;
		}
	}

	myType* findByValue(const myType& elem)
	{
		containerIter iter = find_if(container.begin(), container.end(), predicate(&elem));
		if (iter != container.end()) {
			return *iter;
		} 
		return 0;
	}

	void removeElement(const myType& elem)
	{
		containerIter iter = find_if(container.begin(), container.end(), predicate(&elem));
		if (iter != container.end()) 
		{
			container.erase(iter);
		}
	}

	void removeAllElements()
	{
		container.erase(container.begin(),container.end());
	}

	myType* operator []( int index) {
		if ( 0<= index && index < numberOfElements()){
			containerIter iter = container.begin();
			for (int i = 0; i < index; i++)
			iter++;
			return *iter;
		}
		return 0;
	}
	
	tContainer_t<myType, myTypeContainer>&  operator+=(tContainer_t& addContainer){
		containerIter iter = addContainer.container.begin();
		while (iter!=addContainer.container.end()){
			insertNewElement(*iter);
			iter++;
		}
		addContainer.removeAllElements();
		return *this;
	}
};
